package com.qdu.reducer;

import com.qdu.bean.WeatherBean1;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class AvgPerHourByWeatherReducer extends Reducer<Text, WeatherBean1, Text, WeatherBean1> {

    private WeatherBean1 resultBean = new WeatherBean1();

    @Override
    protected void reduce(Text key, Iterable<WeatherBean1> values, Context context) throws IOException, InterruptedException {

        int sumcasual = 0;
        int sumregistered = 0;
        int count = 0;

        for (WeatherBean1 w:
             values) {
            sumcasual += w.getCasual();
            sumregistered += w.getRegistered();
            count ++ ;
        }

        resultBean.set(sumregistered/count,sumcasual/count);

        context.write(key,resultBean);
    }
}
